package com.mrlong.flutterstudy;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodChannel;

import java.lang.reflect.Method;

public class MainActivity extends FlutterActivity {
    private static final String CHANNEL = "cn.mrlong.study/plugin";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //步骤三：这里接受
        new MethodChannel(getFlutterView(), CHANNEL)
                .setMethodCallHandler(new MethodChannel.MethodCallHandler() {
                    @Override
                    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
                        //步骤四 ： 处理Flutter 传过来的方法名和参数
                        if (methodCall.method.equals("data")) {
                            if (null != methodCall.arguments) {
                                String agus = methodCall.arguments.toString();
                                if (null!=agus&&agus.equals("playerUrl")){
                                    MainActivity.this.startActivity(new Intent(MainActivity.this,PlayActivity.class));
                                    Toast.makeText(MainActivity.this, "Java收到：" + methodCall.arguments.toString(), Toast.LENGTH_SHORT).show();
                                }
                                //步骤五：返回Flutter 值
                                result.success("FromJava=>true");
                            }
                        }
                    }
                });
        GeneratedPluginRegistrant.registerWith(this);
    }
}
